﻿namespace Watch
{
    using DBEmr.BLL;
    using DBEmr.Model;
    using DBUtility;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;
    using Usual;

    public class MainFrm : Form
    {
        private Button button1;
        private Button button2;
        private Button button3;
        private Button button4;
        private Button button5;
        private Button button6;
        private string caption = "提示信息";
        private Container components = null;
        private DataGrid dataGrid1;
        private DataGrid dataGrid2;
		public System.Windows.Forms.DataGrid DataGrid2
		{
			get { return dataGrid2; }
			set { dataGrid2 = value; }
		}
        private DateTimePicker dateTimePicker1;
        private string dep;
        private string dept;
        private string[] dgvColEmp = new string[] { "ID;人员编号", "EM_NAME;姓名", "EM_SEX;性别", "EM_WORKADDRESS;坐诊地址", "EM_STATE;状态", "EM_TELEPHONE;固定电话", "EM_FAMILYADDRESS;家庭地址", "EM_MOBILEPHONE;移动电话" };
        private string[] dgvColWatch = new string[] { "W_ID;值班编号", "DEP_ID;科室编号", "DEP_ID1;科室名称", "EMP_ID;正值班", "EMP_ID_;正值班 ", "EMP_ID1;副值班", "EMP_ID1_;副值班 ", "W_DATE;值班日期", "W_MEMO;备注", "MOD_MAN;排班人", "MOD_MAN_;排班人 ", "MOD_DATE;排班时间" };
        private DataTable dtDept = null;
        private DataTable dtWatch;
        private Label label1;
        private Label label2;
        private string loginID = "000112";
        private string oper;
        private Panel panel1;
        private Panel panel2;
        private RadioButton radioButton1;
        private RadioButton radioButton2;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.DataGrid dataGrid3;
		private System.Windows.Forms.Label textBoxUser;
		private System.Windows.Forms.Label textBoxUserName;
		private System.Windows.Forms.Label textBoxDEPT;
        private string strWhere;
        private UserInfo uinfo;
        private DbHelperOra sql_help;
        public MainFrm()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
			this.panel1 = new System.Windows.Forms.Panel();
			this.textBoxDEPT = new System.Windows.Forms.Label();
			this.textBoxUserName = new System.Windows.Forms.Label();
			this.textBoxUser = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.panel2 = new System.Windows.Forms.Panel();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.button5 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.dataGrid2 = new System.Windows.Forms.DataGrid();
			this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.dataGrid3 = new System.Windows.Forms.DataGrid();
			this.panel1.SuspendLayout();
			this.panel2.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid3)).BeginInit();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.textBoxDEPT);
			this.panel1.Controls.Add(this.textBoxUserName);
			this.panel1.Controls.Add(this.textBoxUser);
			this.panel1.Controls.Add(this.label13);
			this.panel1.Controls.Add(this.label7);
			this.panel1.Controls.Add(this.label6);
			this.panel1.Controls.Add(this.label2);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(634, 32);
			this.panel1.TabIndex = 0;
			// 
			// textBoxDEPT
			// 
			this.textBoxDEPT.Font = new System.Drawing.Font("宋体", 9F);
			this.textBoxDEPT.Location = new System.Drawing.Point(496, 8);
			this.textBoxDEPT.Name = "textBoxDEPT";
			this.textBoxDEPT.Size = new System.Drawing.Size(128, 20);
			this.textBoxDEPT.TabIndex = 20;
			// 
			// textBoxUserName
			// 
			this.textBoxUserName.Font = new System.Drawing.Font("宋体", 9F);
			this.textBoxUserName.Location = new System.Drawing.Point(280, 8);
			this.textBoxUserName.Name = "textBoxUserName";
			this.textBoxUserName.Size = new System.Drawing.Size(128, 20);
			this.textBoxUserName.TabIndex = 19;
			// 
			// textBoxUser
			// 
			this.textBoxUser.Font = new System.Drawing.Font("宋体", 9F);
			this.textBoxUser.Location = new System.Drawing.Point(72, 8);
			this.textBoxUser.Name = "textBoxUser";
			this.textBoxUser.Size = new System.Drawing.Size(128, 20);
			this.textBoxUser.TabIndex = 18;
			// 
			// label13
			// 
			this.label13.AutoSize = true;
			this.label13.Location = new System.Drawing.Point(9, 10);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(66, 17);
			this.label13.TabIndex = 17;
			this.label13.Text = "用户帐号：";
			// 
			// label7
			// 
			this.label7.AutoSize = true;
			this.label7.Location = new System.Drawing.Point(217, 10);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(66, 17);
			this.label7.TabIndex = 13;
			this.label7.Text = "申请医师：";
			// 
			// label6
			// 
			this.label6.AutoSize = true;
			this.label6.Location = new System.Drawing.Point(433, 10);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(66, 17);
			this.label6.TabIndex = 16;
			this.label6.Text = "所属科室：";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(32, 8);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(0, 17);
			this.label2.TabIndex = 0;
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.label4);
			this.panel2.Controls.Add(this.label3);
			this.panel2.Controls.Add(this.button5);
			this.panel2.Controls.Add(this.button6);
			this.panel2.Controls.Add(this.button3);
			this.panel2.Controls.Add(this.button4);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel2.Location = new System.Drawing.Point(0, 391);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(634, 64);
			this.panel2.TabIndex = 1;
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label4.Location = new System.Drawing.Point(88, 24);
			this.label4.Name = "label4";
			this.label4.TabIndex = 14;
			this.label4.Text = "　";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(16, 24);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(66, 17);
			this.label3.TabIndex = 13;
			this.label3.Text = "值班日期：";
			// 
			// button5
			// 
			this.button5.Enabled = false;
			this.button5.Location = new System.Drawing.Point(424, 24);
			this.button5.Name = "button5";
			this.button5.TabIndex = 12;
			this.button5.Text = "保存";
			this.button5.Click += new System.EventHandler(this.buttonS_Click);
			// 
			// button6
			// 
			this.button6.Location = new System.Drawing.Point(520, 24);
			this.button6.Name = "button6";
			this.button6.TabIndex = 11;
			this.button6.Text = "取消";
			this.button6.Click += new System.EventHandler(this.buttonS_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(232, 24);
			this.button3.Name = "button3";
			this.button3.TabIndex = 10;
			this.button3.Text = "新增";
			this.button3.Click += new System.EventHandler(this.buttonS_Click);
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(328, 24);
			this.button4.Name = "button4";
			this.button4.TabIndex = 9;
			this.button4.Text = "修改";
			this.button4.Click += new System.EventHandler(this.buttonS_Click);
			// 
			// dataGrid1
			// 
			this.dataGrid1.CaptionText = "本科医生列表";
			this.dataGrid1.DataMember = "";
			this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Top;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(0, 32);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(634, 152);
			this.dataGrid1.TabIndex = 2;
			// 
			// dataGrid2
			// 
			this.dataGrid2.CaptionText = "本科医生值班表";
			this.dataGrid2.DataMember = "";
			this.dataGrid2.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid2.Location = new System.Drawing.Point(0, 239);
			this.dataGrid2.Name = "dataGrid2";
			this.dataGrid2.ReadOnly = true;
			this.dataGrid2.Size = new System.Drawing.Size(634, 152);
			this.dataGrid2.TabIndex = 3;
			this.dataGrid2.CurrentCellChanged += new System.EventHandler(this.dataGrid2_CurrentCellChanged);
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.CustomFormat = "yyyy-MM-dd";
			this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
			this.dateTimePicker1.Location = new System.Drawing.Point(104, 200);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(88, 21);
			this.dateTimePicker1.TabIndex = 4;
			this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
			// 
			// radioButton1
			// 
			this.radioButton1.Checked = true;
			this.radioButton1.Location = new System.Drawing.Point(232, 200);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(64, 24);
			this.radioButton1.TabIndex = 5;
			this.radioButton1.TabStop = true;
			this.radioButton1.Text = "正值班";
			// 
			// radioButton2
			// 
			this.radioButton2.Location = new System.Drawing.Point(296, 200);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(64, 24);
			this.radioButton2.TabIndex = 6;
			this.radioButton2.Text = "副值班";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(520, 200);
			this.button2.Name = "button2";
			this.button2.TabIndex = 8;
			this.button2.Text = "↑";
			this.button2.Click += new System.EventHandler(this.buttonS_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(424, 200);
			this.button1.Name = "button1";
			this.button1.TabIndex = 7;
			this.button1.Text = "↓";
			this.button1.Click += new System.EventHandler(this.buttonS_Click);
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(32, 204);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(66, 17);
			this.label1.TabIndex = 9;
			this.label1.Text = "值班日期：";
			// 
			// dataGrid3
			// 
			this.dataGrid3.CaptionText = "值班日期";
			this.dataGrid3.DataMember = "";
			this.dataGrid3.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid3.Location = new System.Drawing.Point(460, 32);
			this.dataGrid3.Name = "dataGrid3";
			this.dataGrid3.ReadOnly = true;
			this.dataGrid3.RowHeadersVisible = false;
			this.dataGrid3.Size = new System.Drawing.Size(174, 152);
			this.dataGrid3.TabIndex = 10;
			this.dataGrid3.Visible = false;
			this.dataGrid3.CurrentCellChanged += new System.EventHandler(this.dataGrid3_CurrentCellChanged);
			// 
			// MainFrm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(634, 455);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.dataGrid3);
			this.Controls.Add(this.radioButton2);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.radioButton1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.dataGrid2);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "MainFrm";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "电子病历 - 排班管理";
			this.Load += new System.EventHandler(this.MainFrm_Load);
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid3)).EndInit();
			this.ResumeLayout(false);

		}

        [STAThread]
        private static void Main()
        {
            Application.Run(new MainFrm());
        }

		private TimeSpan tsDateTime;
		private DateTime checkDateTime;
		private string userID;
		private string deptName;
		private string msg=string.Empty;
		private int operRowNo=-1;

		private void MainFrm_Load(object sender, EventArgs e)
        {
            sql_help = new DbHelperOra();
            uinfo = new UserInfo();
			string[] tagStr=Tag.ToString().Split(';');
			tsDateTime=TimeSpan.Parse(tagStr[1]);
            dep = uinfo.GetUserDeptName(textBoxUser.Text);
            dept = uinfo.GetUserDeptID(tagStr[0]);
			loginID=tagStr[0];
			textBoxUser.Text=tagStr[0];
            userID = uinfo.GetUserID(textBoxUser.Text);
            deptName = uinfo.GetUserDeptName(loginID);
            textBoxUserName.Text = uinfo.GetUserName(textBoxUser.Text);
            textBoxDEPT.Text = uinfo.GetUserDeptName(textBoxUser.Text);
			
			dateTimePicker1.Value= checkDateTime=DateTime.Now-tsDateTime;
            read();
			//setDays();
        }

		private void setDays()
		{
			DataTable dt=new DataTable("remainDays");
			Type type=System.Type.GetType("System.Boolean");
			dt.Columns.Add("日期");
			dt.Columns.Add("选择",type);
			DateTime day=checkDateTime;
			while(day.Month==checkDateTime.Month)
			{
				dt.Rows.Add(new object[]{day.ToString("yyyy-MM-dd"),0});
				day=day.AddDays(1);
			}
			dataGrid3.DataSource=dt;
		}
		private void buttonS_Click(object sender, EventArgs e)
		{
			checkDateTime=DateTime.Now-tsDateTime;
			msg=string.Empty;
			switch ((sender as Button).Name)
			{
				case "button1":
					if ((oper == "新增") || (oper == "修改"))
					{
						if (radioButton1.Checked)
						{
							dataGrid2[operRowNo, 3] = dataGrid1[dataGrid1.CurrentRowIndex, 0];
							dataGrid2[operRowNo, 4] = dataGrid1[dataGrid1.CurrentRowIndex, 1];
						}
						else if (radioButton2.Checked)
						{
							dataGrid2[operRowNo, 5] = dataGrid1[dataGrid1.CurrentRowIndex, 0];
							dataGrid2[operRowNo, 6] = dataGrid1[dataGrid1.CurrentRowIndex, 1];
						}
					}
					break;

				case "button2":
					if ((oper == "新增") || (oper == "修改"))
					{
						if (radioButton1.Checked)
						{
							dataGrid2[operRowNo, 3] = string.Empty;
							dataGrid2[operRowNo, 4] = string.Empty;
						}
						else if (radioButton2.Checked)
						{
							dataGrid2[operRowNo, 5] = string.Empty;
							dataGrid2[operRowNo, 6] = string.Empty;
						}
					}
					break;
				case "button3":
					if (dateTimePicker1.Value.Date>=checkDateTime.Date && 
						!dtWatch.Rows.Contains(new object[] { dateTimePicker1.Value.ToString("yyyy-MM-dd") }))
					{
						string strWID=string.Empty;
						strWID= sql_help.GetMaxID("W_ID","WATCH").ToString("D6");
						dtWatch.Rows.Add(new object[] { strWID, dept, deptName, "", "", "", "",uinfo.GetUserID(loginID),uinfo.GetUserName(loginID), dateTimePicker1.Value.ToString("yyyy-MM-dd"),checkDateTime.ToString("yyyy-MM-dd HH:mm:ss")});
						oper = (sender as Button).Text;
						button3.Enabled = false;
						button4.Enabled = false;
						button5.Enabled = true;
						operRowNo=/*(dataGrid2.DataSource as DataTable)*/dtWatch.Rows.Count-1;
						dataGrid2.CurrentRowIndex=operRowNo;
						dataGrid2.Enabled=false;
					}
					else
					{
						msg=string.Format("【{0}】值班已经安排！",dateTimePicker1.Value.ToString("yyyy-MM-dd"));
					}
					break;
				case "button4":
					if(checkDateTime<=DateTime.Parse(dataGrid2[dataGrid2.CurrentRowIndex,9].ToString()))
					{
						oper = (sender as Button).Text;
						button3.Enabled = false;
						button4.Enabled = false;
						button5.Enabled = true;
						dataGrid2.Enabled=false;
						operRowNo=dataGrid2.CurrentRowIndex;
					}
					else
					{
						msg=string.Format("不能修改今日以前的排班记录！",dateTimePicker1.Value.ToString("yyyy-MM-dd"));
					}
					break;
				case "button5":
					DBEmr.BLL.WATCH bll_WATCH = new DBEmr.BLL.WATCH();
					DBEmr.Model.WATCH model_WATCH = new DBEmr.Model.WATCH();
					dataGrid2.Enabled=true;
					try
					{
						if (oper == "新增")
						{
							model_WATCH.W_ID = dataGrid2[operRowNo, 0].ToString();
							model_WATCH.W_DATE = dataGrid2[operRowNo, 9].ToString();
							model_WATCH.MOD_DATE = dataGrid2[operRowNo, 10].ToString();
							model_WATCH.MOD_MAN = userID;
							model_WATCH.DEP_ID = dept;
							model_WATCH.EMP_ID = dataGrid2[operRowNo, 3].ToString();
							model_WATCH.EMP_ID1 = dataGrid2[operRowNo, 5].ToString();
							model_WATCH.W_MEMO = "";
							bll_WATCH.Add(model_WATCH);
						}
						else if (oper == "修改")
						{
							model_WATCH.W_ID = dataGrid2[operRowNo, 0].ToString();
							model_WATCH.W_DATE = dataGrid2[operRowNo, 9].ToString();
							model_WATCH.MOD_DATE = checkDateTime.ToString("yyyy-MM-dd HH:mm:ss");
							model_WATCH.MOD_MAN = userID;
							model_WATCH.DEP_ID = dept;
							model_WATCH.EMP_ID = dataGrid2[operRowNo, 3].ToString();
							model_WATCH.EMP_ID1 = dataGrid2[operRowNo, 5].ToString();
							model_WATCH.W_MEMO = "";
							bll_WATCH.Update(model_WATCH);
						}
						msg=string.Format("【{0}】的值班保存成功！",dateTimePicker1.Value.ToString("yyyy-MM-dd"));
					}
					catch (System.Exception ex)
					{
						msg=ex.Message;
					}
					read();
					button3.Enabled = true;
					button4.Enabled = true;
					button5.Enabled = false;
					break;
				case "button6":
					read();
					if (dataGrid2.CurrentRowIndex>-1)
						label4.Text=dataGrid2[dataGrid2.CurrentRowIndex,9].ToString();
					dataGrid2.Enabled=true;
					button3.Enabled = true;
					button4.Enabled = true;
					button5.Enabled = false;
					break;
			}
			if(msg.Length>0)
				MessageBox.Show(msg, "提示信息", MessageBoxButtons.OK,MessageBoxIcon.Information);
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

        private DataTable makeDTWatch()
        {
            DataTable dtWatch = new DataTable("WATCH");
            for (int i = 0; i < dgvColWatch.Length; i++)
            {
                dtWatch.Columns.Add(dgvColWatch[i].Split(new char[] { ';' })[0]);
            }
            dtWatch.PrimaryKey = new DataColumn[] { dtWatch.Columns["W_DATE"] };
            return dtWatch;
        }

        private void read()
        {
            strWhere = "SELECT ID,EM_NAME,EM_SEX,EM_WORKADDRESS,EM_STATE,EM_TELEPHONE,EM_FAMILYADDRESS,EM_MOBILEPHONE FROM EMPLOYEE WHERE ID IN(SELECT EMP_ID FROM emp_dep_connection WHERE DEP_ID LIKE '" + dept + "')";
            dtDept = sql_help.Query(strWhere).Tables[0];
			DTableClass.SetDBNull(ref dtDept);
            dataGrid1.DataSource = dtDept;
            DTableClass.ChangeColNameForDataTable(ref dtDept, dgvColEmp, true);
			strWhere="select t.w_id,t.dep_id,(select a.name from department a where a.id=t.dep_id) as dep_id1, t.emp_id, (select a.em_name from employee a where a.id=t.emp_id) as emp_id_,t.emp_id1, (select a.em_name from employee a where a.id=t.emp_id1) as emp_id1_,t.mod_man, (select a.em_name from employee a where a.id=t.mod_man) as mod_man_,t.w_date,t.mod_date from watch t"+string.Format(" where Dep_id like '{0}' and to_char(to_date(w_date,'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM')='{1}' order by w_date",dept,dateTimePicker1.Value.ToString("yyyy-MM"));
			dtWatch=sql_help.Query(strWhere).Tables[0];
			if(dtWatch!=null/* && dtWatch.Rows.Count>=0*/)
			{
				DTableClass.SetDBNull(ref dtWatch);
				dtWatch.PrimaryKey = new DataColumn[] { dtWatch.Columns["W_DATE"] };
				DTableClass.ChangeColNameForDataTable(ref dtWatch, dgvColWatch, true);
				dataGrid2.DataSource = dtWatch;
			}
			else
			{
				dataGrid2.DataSource=null;
			}
        }

		private void dataGrid2_CurrentCellChanged(object sender, System.EventArgs e)
		{
			label4.Text=dataGrid2[dataGrid2.CurrentRowIndex,9].ToString();
		}

		private void dataGrid3_CurrentCellChanged(object sender, System.EventArgs e)
		{
			if (dataGrid3.CurrentCell.ColumnNumber==1)
			{
				dataGrid3[dataGrid3.CurrentRowIndex,1]=!bool.Parse(dataGrid3[dataGrid3.CurrentRowIndex,1].ToString());
			}
		}

		private void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
		{
			read();
		}
    }
}

